import 'package:elephant_fish/http/core/hi_error.dart';
import 'package:elephant_fish/model/video.dart';
import 'package:elephant_fish/page/history_play_page.dart';
import 'package:elephant_fish/page/perfect_information_page.dart';
import 'package:elephant_fish/widget/video_card.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';

import 'index_home_page.dart';
import 'login_page.dart';

class IndexHistoryPlayPage extends StatefulWidget {
  const IndexHistoryPlayPage({Key key}) : super(key: key);

  @override
  _IndexHistoryPlayPageState createState() => _IndexHistoryPlayPageState();
}

class _IndexHistoryPlayPageState extends State<IndexHistoryPlayPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        backgroundColor: Color(0xff140c3c),
        title: Text('历史播放',style: TextStyle(fontSize: 16,color: Color(0xfff5f5f5) ),),
        leading: GestureDetector(
          onTap: (){
            Navigator.pop(context);
          },
          child: Icon(Icons.arrow_back_ios,size: 16,color: Color(0xfff3f3f3),),
        ),

      ),
      body: DefaultTabController(
        length: 5,
        child: Scaffold(
            floatingActionButtonLocation:
            FloatingActionButtonLocation.centerDocked,
            floatingActionButton: FloatingActionButton(
              foregroundColor: Color(0xff),
              backgroundColor: Color(0xff140c3c),
              child: Icon(
                Icons.circle,
                size: 50,
                color: Color(0xffff215d),
              ),
              onPressed: () {
                print('中间大键');
              },
            ),
            bottomNavigationBar: buildBottomNavigation(),
            body: IndexedStack(
              sizing: StackFit.expand,
              index: currentIndex,
              children: bodyWidgetList,
            )),
      ),
    );
  }

  ///选中的标签
  int currentIndex = 0;

  ///图标区
  List<String> normalIcon = [
    "assets/images/home.png",
    "assets/images/shop.png",
    "assets/images/message.png",
    "assets/images/my.png",
    "assets/images/home_checked.png",
    "assets/images/shop_checked.png",
    "assets/images/message_checked.png",
    "assets/images/my_checked.png",
  ];

  List<String> normalTitle = ["首页", "商城", "消息", "我的"];

  List<Widget> bodyWidgetList = [
    HistoryPlayPage(),
    PerfectInformationPage(),
    PerfectInformationPage(),
    PerfectInformationPage()
  ];

  BottomAppBar buildBottomNavigation() {
    double itemWidth = MediaQuery.of(context).size.width / 5;
    return BottomAppBar(
      color: Color(0xff140c3c),
      // shape: CircularNotchedRectangle(),
      child: Row(
        children: [
          SizedBox(height: 49, width: itemWidth, child: bottomAppBarItem(0)),
          SizedBox(height: 49, width: itemWidth, child: bottomAppBarItem(1)),
          SizedBox(height: 49, width: itemWidth),
          SizedBox(height: 49, width: itemWidth, child: bottomAppBarItem(2)),
          SizedBox(height: 49, width: itemWidth, child: bottomAppBarItem(3))
        ],
      ),
    );
  }

  Widget bottomAppBarItem(int index) {
    //设置默认未选中的状态
    TextStyle style = TextStyle(fontSize: 10, color: Color(0xfff3f3f3));
    // String imgUrl = normalImgUrls[index];
    String imgUrl = normalIcon[index];
    if (currentIndex == index) {
      //选中的话
      style = TextStyle(fontSize: 10, color: Color(0xfff3f3f3));
      // imgUrl = selectedImgUrls[index];
      imgUrl = normalIcon[index + 4] ;
    }
    //构造返回的Widget
    Widget item = Container(
      child: GestureDetector(
        behavior: HitTestBehavior.opaque,
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            Image.asset(imgUrl, width: 32,),
            // normalIcon[index],
            Text(
              normalTitle[index],
              style: style,
            ),
          ],
        ),
        onTap: () {
          if (currentIndex != index) {
            setState(() {
              currentIndex = index;
              print(index);
            });
          }
        },
      ),
    );
    return item;
  }

}
